package edu.uoc.tdp.pac4.client.gestion;

import edu.uoc.tdp.pac4.EAssistencia;
import edu.uoc.tdp.pac4.beans.Curso;
import edu.uoc.tdp.pac4.beans.Grupo;
import edu.uoc.tdp.pac4.exceptions.GroupNotEmptyException;
import edu.uoc.tdp.pac4.remote.GestAcademica;
import edu.uoc.tdp.pac4.util.ComboItem;
import edu.uoc.tdp.pac4.util.DateTimeUtils;
import edu.uoc.tdp.pac4.util.LanguageUtils;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 * Implementa el formulario de gestión de grupos.
 * 
 * @author eSupport Netbeans
 */
public class PnlGroupGestor extends javax.swing.JDialog 
{
   private GestAcademica manager;
   private LanguageUtils language;
   private ArrayList<Grupo> grupos;

   /**
    * Creates new form PnlGroupGestor
    */
   public PnlGroupGestor(java.awt.Frame parent, boolean modal, GestAcademica manager, LanguageUtils language)
   {
      super(parent, modal);
      initComponents();
      
      setLocationRelativeTo(null);
      pnlFilter.setVisible(false);

      this.manager = manager;
      this.language = language;
      
      setLanguage();
      fillForm();
   }

   /**
    * This method is called from within the constructor to initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is always
    * regenerated by the Form Editor.
    */
   @SuppressWarnings("unchecked")
   // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
   private void initComponents() {

      jToolBar1 = new javax.swing.JToolBar();
      cmdAdd = new javax.swing.JButton();
      cmdEdit = new javax.swing.JButton();
      cmdDelete = new javax.swing.JButton();
      jSeparator1 = new javax.swing.JToolBar.Separator();
      cmdFilter = new javax.swing.JToggleButton();
      cmdClose = new javax.swing.JButton();
      jScrollPane1 = new javax.swing.JScrollPane();
      grdTable = new javax.swing.JTable();
      pnlFilter = new javax.swing.JPanel();
      lblTurno = new javax.swing.JLabel();
      lblCurso = new javax.swing.JLabel();
      cboCurso = new javax.swing.JComboBox();
      cmdSetFilter = new javax.swing.JButton();
      lblFechaIni = new javax.swing.JLabel();
      lblFechaFin = new javax.swing.JLabel();
      cboTurno = new javax.swing.JComboBox();
      cmdFilterDelete = new javax.swing.JButton();
      txtFechaInicio = new javax.swing.JFormattedTextField();
      txtFechaFin = new javax.swing.JFormattedTextField();

      setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
      setTitle("Gestión de grupos");

      jToolBar1.setRollover(true);

      cmdAdd.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/users--plus.png"))); // NOI18N
      cmdAdd.setText("Nuevo");
      cmdAdd.setFocusable(false);
      cmdAdd.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
      cmdAdd.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
      cmdAdd.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            cmdAddActionPerformed(evt);
         }
      });
      jToolBar1.add(cmdAdd);

      cmdEdit.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/users--pencil.png"))); // NOI18N
      cmdEdit.setText("Editar");
      cmdEdit.setFocusable(false);
      cmdEdit.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
      cmdEdit.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
      cmdEdit.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            cmdEditActionPerformed(evt);
         }
      });
      jToolBar1.add(cmdEdit);

      cmdDelete.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/users--minus.png"))); // NOI18N
      cmdDelete.setText("Eliminar");
      cmdDelete.setFocusable(false);
      cmdDelete.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
      cmdDelete.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
      cmdDelete.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            cmdDeleteActionPerformed(evt);
         }
      });
      jToolBar1.add(cmdDelete);
      jToolBar1.add(jSeparator1);

      cmdFilter.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/funnel.png"))); // NOI18N
      cmdFilter.setText("Filtrar");
      cmdFilter.setFocusable(false);
      cmdFilter.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
      cmdFilter.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
      cmdFilter.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            cmdFilterActionPerformed(evt);
         }
      });
      jToolBar1.add(cmdFilter);

      cmdClose.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/arrow-curve-180.png"))); // NOI18N
      cmdClose.setText("Cerrar");
      cmdClose.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            cmdCloseActionPerformed(evt);
         }
      });

      grdTable.setModel(new javax.swing.table.DefaultTableModel(
         new Object [][] {
            {null, null, null, null},
            {null, null, null, null},
            {null, null, null, null},
            {null, null, null, null}
         },
         new String [] {
            "Title 1", "Title 2", "Title 3", "Title 4"
         }
      ));
      jScrollPane1.setViewportView(grdTable);

      pnlFilter.setBorder(javax.swing.BorderFactory.createEtchedBorder());

      lblTurno.setText("Turno");

      lblCurso.setText("Curso");

      cmdSetFilter.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/funnel--plus.png"))); // NOI18N
      cmdSetFilter.setText("Aplicar");
      cmdSetFilter.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            cmdSetFilterActionPerformed(evt);
         }
      });

      lblFechaIni.setText("Fecha inicio");

      lblFechaFin.setText("Fecha finalización");

      cmdFilterDelete.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/eraser.png"))); // NOI18N
      cmdFilterDelete.setText("Limpiar");
      cmdFilterDelete.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            cmdFilterDeleteActionPerformed(evt);
         }
      });

      txtFechaInicio.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(new java.text.SimpleDateFormat("dd/MM/yyyy"))));
      txtFechaInicio.setToolTipText("Format: dd/mm/yyyy"); // NOI18N

      txtFechaFin.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.DateFormatter(new java.text.SimpleDateFormat("dd/MM/yyyy"))));
      txtFechaFin.setToolTipText("Format: dd/mm/yyyy");

      javax.swing.GroupLayout pnlFilterLayout = new javax.swing.GroupLayout(pnlFilter);
      pnlFilter.setLayout(pnlFilterLayout);
      pnlFilterLayout.setHorizontalGroup(
         pnlFilterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
         .addGroup(pnlFilterLayout.createSequentialGroup()
            .addContainerGap()
            .addGroup(pnlFilterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
               .addComponent(lblCurso)
               .addComponent(lblTurno))
            .addGap(18, 18, 18)
            .addGroup(pnlFilterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
               .addComponent(cboCurso, javax.swing.GroupLayout.PREFERRED_SIZE, 239, javax.swing.GroupLayout.PREFERRED_SIZE)
               .addComponent(cboTurno, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGap(27, 27, 27)
            .addGroup(pnlFilterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
               .addComponent(lblFechaFin)
               .addComponent(lblFechaIni))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
            .addGroup(pnlFilterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
               .addComponent(txtFechaInicio, javax.swing.GroupLayout.DEFAULT_SIZE, 104, Short.MAX_VALUE)
               .addComponent(txtFechaFin))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(pnlFilterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
               .addComponent(cmdSetFilter, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
               .addComponent(cmdFilterDelete, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addContainerGap())
      );
      pnlFilterLayout.setVerticalGroup(
         pnlFilterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
         .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlFilterLayout.createSequentialGroup()
            .addContainerGap()
            .addGroup(pnlFilterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
               .addComponent(lblCurso)
               .addComponent(cboCurso, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
               .addComponent(lblFechaIni)
               .addComponent(cmdFilterDelete)
               .addComponent(txtFechaInicio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
            .addGroup(pnlFilterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
               .addComponent(lblFechaFin)
               .addComponent(lblTurno)
               .addComponent(cboTurno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
         .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlFilterLayout.createSequentialGroup()
            .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(pnlFilterLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
               .addComponent(cmdSetFilter)
               .addComponent(txtFechaFin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addContainerGap())
      );

      javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
      getContentPane().setLayout(layout);
      layout.setHorizontalGroup(
         layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
         .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
         .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
               .addComponent(pnlFilter, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
               .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 658, Short.MAX_VALUE)
               .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                  .addGap(0, 0, Short.MAX_VALUE)
                  .addComponent(cmdClose)))
            .addContainerGap())
      );
      layout.setVerticalGroup(
         layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
         .addGroup(layout.createSequentialGroup()
            .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(pnlFilter, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 262, Short.MAX_VALUE)
            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
            .addComponent(cmdClose)
            .addContainerGap())
      );

      pack();
   }// </editor-fold>//GEN-END:initComponents

   private void cmdAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdAddActionPerformed

      PnlGroup form = new PnlGroup(null, true ,manager, language);
      form.setLocationRelativeTo(null);
      form.setVisible(true);

      fillForm();
   }//GEN-LAST:event_cmdAddActionPerformed

   private void cmdEditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdEditActionPerformed

      if (grdTable.getSelectedRow() < 0)
      {
         JOptionPane.showMessageDialog(null,
                                       language.getProperty(EAssistencia.FORM_PNLGROUPGESTOR_WARN_EDITGRUPO),
                                       language.getProperty(EAssistencia.APP_TITLE),
                                       JOptionPane.WARNING_MESSAGE);
         return;
      }

      // Obtiene el ID del grupo a editar
      Grupo grupo = grupos.get(grdTable.getSelectedRow());

      PnlGroup form = new PnlGroup(null, true, manager, language, grupo.getId());
      form.setLocationRelativeTo(null);
      form.setVisible(true);

      fillForm();

   }//GEN-LAST:event_cmdEditActionPerformed

   private void cmdCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdCloseActionPerformed

      // Cierra el formulario
      this.dispose();

   }//GEN-LAST:event_cmdCloseActionPerformed

   private void cmdDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdDeleteActionPerformed
      
      if (grdTable.getSelectedRow() < 0)
      {
         JOptionPane.showMessageDialog(null,
                                       language.getProperty(EAssistencia.FORM_PNLGROUPGESTOR_WARN_DELETEGRUPO),
                                       language.getProperty(EAssistencia.APP_TITLE),
                                       JOptionPane.WARNING_MESSAGE);
         return;
      }
      
      // Confirma la acción antes de efectuarla
      if (JOptionPane.showConfirmDialog(null,
                                        language.getProperty(EAssistencia.FORM_PNLGROUPGESTOR_WARN_DELETECONFIRM),
                                        language.getProperty(EAssistencia.APP_TITLE),
                                        JOptionPane.YES_NO_OPTION,
                                        JOptionPane.WARNING_MESSAGE) == JOptionPane.NO_OPTION)
      {
         return;
      }
      
      try 
      {
         // Obtiene el grupo seleccionado y lo elimina
         Grupo grupo = grupos.get(grdTable.getSelectedRow());
         manager.deleteGrupo(grupo.getId());
         
         // Refresca el listado
         fillForm();
      } 
      catch (GroupNotEmptyException ex)
      {
         JOptionPane.showMessageDialog(null, 
                                       language.getProperty(EAssistencia.ERROR_GROUPNOTEMPTY), 
                                       language.getProperty(EAssistencia.APP_TITLE), 
                                       JOptionPane.ERROR_MESSAGE);
         
         // Registra el error en un archivo de LOG
         // Logger.getLogger(FrmResourcesRequest.class.getName()).log(Level.SEVERE, null, ex);
      }
      catch (Exception ex) 
      {
         JOptionPane.showMessageDialog(null, 
                                       language.getProperty(EAssistencia.ERROR_GENERIC) + "\n" + language.getProperty(EAssistencia.ERROR_DETAILS) + ":\n\n" + ex.getMessage(), 
                                       language.getProperty(EAssistencia.APP_TITLE), 
                                       JOptionPane.ERROR_MESSAGE);
         
         // Registra el error en un archivo de LOG
         // Logger.getLogger(FrmResourcesRequest.class.getName()).log(Level.SEVERE, null, ex);
      }
   }//GEN-LAST:event_cmdDeleteActionPerformed

   private void cmdSetFilterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdSetFilterActionPerformed

      int idCurso = (cboCurso.getSelectedIndex() >= 0 ? ((Curso)cboCurso.getSelectedItem()).getId() : -1);
      int idTurno = (cboTurno.getSelectedIndex() >= 0 ? ((ComboItem)cboTurno.getSelectedItem()).getId() : -1);
      
      Date fechaIni = (DateTimeUtils.isDate(txtFechaInicio.getText()) ? DateTimeUtils.strToDate(txtFechaInicio.getText()) : null);
      Date fechaFin = (DateTimeUtils.isDate(txtFechaFin.getText()) ? DateTimeUtils.strToDate(txtFechaFin.getText()) : null);

      fillForm(idCurso, idTurno, fechaIni, fechaFin);

   }//GEN-LAST:event_cmdSetFilterActionPerformed

   private void cmdFilterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdFilterActionPerformed
      
      pnlFilter.setVisible(cmdFilter.isSelected());
      
      // Si se oculta el filtro, se regenera la lista completa
      if (!pnlFilter.isVisible())
      {
         fillForm();
      }
      else
      {
         fillFilterPanel();
      }
   }//GEN-LAST:event_cmdFilterActionPerformed

   private void cmdFilterDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdFilterDeleteActionPerformed
      
      fillFilterPanel();
      
   }//GEN-LAST:event_cmdFilterDeleteActionPerformed

   /**
    * Rellena el panel de filtros.
    */
   private void fillFilterPanel() 
   {
      try 
      {
         // Rellena la lista de cursos
         cboCurso.removeAll();
         cboCurso.setModel(new DefaultComboBoxModel(manager.getCursos().toArray()));
         cboCurso.setSelectedIndex(-1);

         // Rellena el combo de filtros
         ArrayList<ComboItem> turnos = new ArrayList<ComboItem>();
         turnos.add(new ComboItem(Grupo.getTurnoName(Grupo.TURNO_MANANA, language), Grupo.TURNO_MANANA));
         turnos.add(new ComboItem(Grupo.getTurnoName(Grupo.TURNO_TARDE, language), Grupo.TURNO_TARDE));
         cboTurno.removeAll();
         cboTurno.setModel(new DefaultComboBoxModel(turnos.toArray()));
         cboTurno.setSelectedIndex(-1);
         
         txtFechaInicio.setValue(null);
         txtFechaFin.setValue(null);
      } 
      catch (Exception ex) 
      {
         JOptionPane.showMessageDialog(null, 
                                       language.getProperty(EAssistencia.FORM_PNLGROUPGESTOR_ERR_LOADFILTER) + "\n\n" + language.getProperty(EAssistencia.ERROR_DETAILS) + ":\n" + ex.getMessage(), 
                                       language.getProperty(EAssistencia.APP_TITLE), 
                                       JOptionPane.ERROR_MESSAGE);
         
         // Registra el error en un archivo de LOG
         // Logger.getLogger(FrmResourcesRequest.class.getName()).log(Level.SEVERE, null, ex);
      }
   }

   /**
    * Internacionaliza los textos del formulario.
    */
   private void setLanguage()
   {
      this.setTitle(language.getProperty(EAssistencia.FORM_PNLGROUPGESTOR_TITLE));
      cmdAdd.setText(language.getProperty(EAssistencia.FORM_PNLGROUPGESTOR_ADD));
      cmdEdit.setText(language.getProperty(EAssistencia.FORM_PNLGROUPGESTOR_EDIT));
      cmdDelete.setText(language.getProperty(EAssistencia.FORM_PNLGROUPGESTOR_DELETE));
      cmdFilter.setText(language.getProperty(EAssistencia.FORM_PNLGROUPGESTOR_FILTER));
      cmdClose.setText(language.getProperty(EAssistencia.FORM_COMMON_CLOSE));
      cmdSetFilter.setText(language.getProperty(EAssistencia.FORM_COMMON_APPLY));
      cmdFilterDelete.setText(language.getProperty(EAssistencia.FORM_COMMON_CLEAN));
      lblCurso.setText(language.getProperty(EAssistencia.FORM_PNLGROUPGESTOR_CURSO));
      lblTurno.setText(language.getProperty(EAssistencia.FORM_PNLGROUPGESTOR_TURNO));
      lblFechaIni.setText(language.getProperty(EAssistencia.FORM_PNLGROUPGESTOR_FECHAINI));
      lblFechaFin.setText(language.getProperty(EAssistencia.FORM_PNLGROUPGESTOR_FECHAFIN));
   }
   
   /**
    * Confecciona el listado completo.
    */
   private void fillForm()
   {
      fillForm(-1, -1, null, null);
   }
   
   /**
    * Confecciona el listado filtrado.
    */
   private void fillForm(int idCurso, int idTurno, Date fechaInicio, Date fechaFin)
   {
      SimpleDateFormat df = new SimpleDateFormat(language.getProperty(EAssistencia.FORMAT_SHORTDATE));
      
      // Rellena la tabla
      ArrayList<String> header = new ArrayList<String>();   // cabecera
      header.add(language.getProperty(EAssistencia.FORM_PNLGROUPGESTOR_NOMBRE));
      header.add(language.getProperty(EAssistencia.FORM_PNLGROUPGESTOR_CURSO));
      header.add(language.getProperty(EAssistencia.FORM_PNLGROUPGESTOR_TURNO));
      header.add(language.getProperty(EAssistencia.FORM_PNLGROUPGESTOR_MAXALUMNOS));
      header.add(language.getProperty(EAssistencia.FORM_PNLGROUPGESTOR_FECHAINI));
      header.add(language.getProperty(EAssistencia.FORM_PNLGROUPGESTOR_FECHAFIN));
      header.add(language.getProperty(EAssistencia.FORM_PNLGROUPGESTOR_PROFESOR));
      header.add(language.getProperty(EAssistencia.FORM_PNLGROUPGESTOR_AULA));
      
      String[][] gridData;
      ArrayList<String> row;

      try 
      {
         // Rellena el listado de grupos
         grupos = manager.getGrupos(idCurso, idTurno, fechaInicio, fechaFin);
         gridData = new String[grupos.size()][8];
         int i = 0;
         for (Grupo grupo : grupos)
         {
            gridData[i][0] = grupo.getNombre();
            gridData[i][1] = grupo.getNombreCurso();
            gridData[i][2] = (grupo.getTurno() == Grupo.TURNO_MANANA ? language.getProperty(EAssistencia.GRUPO_TURNO_MANANA) : language.getProperty(EAssistencia.GRUPO_TURNO_TARDE));
            gridData[i][3] = "" + grupo.getMaxAlumnos();
            gridData[i][4] = (grupo.getFechaInicioCurso() == null ? "?" : df.format(grupo.getFechaInicioCurso()));
            gridData[i][5] = (grupo.getFechaFinCurso() == null ? "?" : df.format(grupo.getFechaFinCurso()));
            gridData[i][6] = grupo.getNombreProfesor();
            gridData[i][7] = grupo.getNombreAula();
            i++;
         }
         
         // Evita que las celdas se puedan editar
         grdTable.setModel(new DefaultTableModel(gridData, header.toArray()) { 
            @Override public boolean isCellEditable(int row, int column)
            { 
               return false; 
            } 
         });
         // grdTable.setModel(new DefaultTableModel(gridData, header.toArray()));
      } 
      catch (Exception ex) 
      {
         JOptionPane.showMessageDialog(null, 
                                       language.getProperty(EAssistencia.ERROR_GENERIC) + "\n" + language.getProperty(EAssistencia.ERROR_DETAILS) + ":\n\n" + ex.getMessage(), 
                                       language.getProperty(EAssistencia.APP_TITLE), 
                                       JOptionPane.ERROR_MESSAGE);
         
         // Registra el error en un archivo de LOG
         // Logger.getLogger(FrmResourcesRequest.class.getName()).log(Level.SEVERE, null, ex);
      }
   }
   
   // Variables declaration - do not modify//GEN-BEGIN:variables
   private javax.swing.JComboBox cboCurso;
   private javax.swing.JComboBox cboTurno;
   private javax.swing.JButton cmdAdd;
   private javax.swing.JButton cmdClose;
   private javax.swing.JButton cmdDelete;
   private javax.swing.JButton cmdEdit;
   private javax.swing.JToggleButton cmdFilter;
   private javax.swing.JButton cmdFilterDelete;
   private javax.swing.JButton cmdSetFilter;
   private javax.swing.JTable grdTable;
   private javax.swing.JScrollPane jScrollPane1;
   private javax.swing.JToolBar.Separator jSeparator1;
   private javax.swing.JToolBar jToolBar1;
   private javax.swing.JLabel lblCurso;
   private javax.swing.JLabel lblFechaFin;
   private javax.swing.JLabel lblFechaIni;
   private javax.swing.JLabel lblTurno;
   private javax.swing.JPanel pnlFilter;
   private javax.swing.JFormattedTextField txtFechaFin;
   private javax.swing.JFormattedTextField txtFechaInicio;
   // End of variables declaration//GEN-END:variables
}
